package com.example.activityproject;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class RedActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.red_activity_layout);
        //获取Intent对象，
        Intent intent = getIntent();
        //通过Intent对象获取Bundle对象，
        Bundle bundle = intent.getExtras();
        //有了bundle对象就可以通过键拿到对应值
        String name = (String) bundle.get("name");
        String age = (String) bundle.get("age");

        Log.i("RedAct","name: "+name+" ,  age: "+ age);

        Button done_bt = findViewById(R.id.done_bt);
        Button close_red_act_bt = findViewById(R.id.close_red_act_bt);
        done_bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent2 = getIntent();
                //返回传值
                intent2.putExtra("result_key","返回值为10000");
                RedActivity.this.setResult(500,intent2);
                //关掉RedActivity界面
                RedActivity.this.finish();
            }
        });

        close_red_act_bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RedActivity.this.finish();
            }
        });

    }
}
